import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'
import Vant from 'vant';
// import 'vant/lib/index.css';
import 'vant/lib/index.less';
Vue.prototype.$EventBus = new Vue()

var _ = require('lodash');
Vue.prototype._ = _;
import directive from './directive' // directive
import plugins from './plugins' // plugins

Vue.use(directive)
Vue.use(plugins)

import 'normalize.css'
import './style/index.css';
import './icons' // icon
Vue.use(Vant);
Vue.config.productionTip = false
// import 'lib-flexible'  // 引入适配包
import Calendar from 'vue-mobile-calendar'
Vue.use(Calendar);
router.beforeEach(async (to, from, next) => { 
  const isLogin = await store.dispatch('validatorLogin'); 
  const needLogin = to.matched.some(match => match.meta.needLogin);
  if (needLogin) { 
      if (isLogin) { 
          next()
      } else { 
          next('/login') 
      }
  } else { 
      if (isLogin && to.name === 'login') { 
          next('/home') 
      } else { 
          next() 
      }
  } 
}) 

Vue.config.productionTip = false
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')
